package channelStatus

import (
	"gitee.com/fierce_wolf/go-fox-edge-common/commRedisService"
	"gitee.com/fierce_wolf/go-fox-edge-common/commUtil/Map"
	"time"
)

type channelTraffic struct {
}

func (e *channelTraffic) ActiveTrafficUploadPack(channelName string) error {
	exist, err := Status.getChannelStatus(channelName)
	if err != nil {
		return err
	}
	if exist == nil {
		return nil
	}
	if exist.ChannelTraffic == nil {
		exist.ChannelTraffic = make(map[string]interface{})
	}

	value := Map.GetInt64(exist.ChannelTraffic, "uploadPack", 0)
	exist.ChannelTraffic["uploadPack"] = value + 1
	exist.ChannelTraffic["uploadTime"] = time.Now().UnixMilli()

	return commRedisService.UpdateEntity(exist)
}

func (e *channelTraffic) ActiveTrafficDownloadPack(channelName string) error {
	exist, err := Status.getChannelStatus(channelName)
	if err != nil {
		return err
	}
	if exist == nil {
		return nil
	}
	if exist.ChannelTraffic == nil {
		exist.ChannelTraffic = make(map[string]interface{})
	}

	value := Map.GetInt64(exist.ChannelTraffic, "downloadPack", 0)
	exist.ChannelTraffic["downloadPack"] = value + 1
	exist.ChannelTraffic["downloadTime"] = time.Now().UnixMilli()

	return commRedisService.UpdateEntity(exist)
}
